﻿#include <QFile>
#include "CVideoLargeDlg.h"
#include "CGlobal.h"
#include "Public.h"

CVideoLargeDlg::CVideoLargeDlg(CDevBeltRealign* pDev, int nType, QWidget *parent)
	: m_pDev(pDev),m_nType(nType),QDialog(parent)
{
	ui.setupUi(this);
	setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
	this->setWindowTitle(A2T("摄像头监控画面"));
	// 获取 Qt 窗口的原生 HWND 句柄
	HWND hwnd = reinterpret_cast<HWND>(this->winId());
	setWindowsTitleBarColor(hwnd, RGB(56, 63, 81));
	setStyleSheetFile();
	connect(ui.pushButtonVideoPlay_2, &QPushButton::clicked, this, &CVideoLargeDlg::slotPushPlay);
	m_bIsPlaying = false;
	startPlayVideo();
}

CVideoLargeDlg::~CVideoLargeDlg()
{
	endPlayVideo();
}

void CVideoLargeDlg::setStyleSheetFile()
{
	QString sQssPath = ":/qss/styleSheet.css";
	QFile qss(sQssPath);
	qss.open(QFile::ReadOnly);
	this->setStyleSheet(qss.readAll());
}

bool CVideoLargeDlg::endPlayVideo()
{
	if (!m_pDev->m_pDevData->m_pDevDataCam->m_bLogin)
		return false;
	if (m_bIsPlaying == false)
		return true;
	SCtrInfo infoTx;
	infoTx.m_pLabel = ui.label;
	infoTx.m_hWid = ui.label->winId();
	infoTx.m_sGuid = m_pDev->m_sPointGuid;
	infoTx.m_nCtrCmd = enCStopRealPlay;
	infoTx.m_nCtrDevType = enSubDev1;
	if (m_nType == 0)
	{
		infoTx.m_nSubCtrDevType = enCamer;
	}
	else if (m_nType == 1)
	{
		infoTx.m_nSubCtrDevType = enIR;
	}
	infoTx.m_nSubCtrDevType = enCamer;
	bool bTxRet = m_pDev->ctrDev(infoTx);
	if (bTxRet == true)
	{
		m_bIsPlaying = false;
		ui.pushButtonVideoPlay_2->setIcon(QIcon(":/icon/play.png"));
	}
	return bTxRet;
}

bool CVideoLargeDlg::startPlayVideo()
{
	if (!m_pDev->m_pDevData->m_pDevDataCam->m_bLogin)
		return false;
	if (m_bIsPlaying)
		return true;
	SCtrInfo infoTx;
	infoTx.m_pLabel = ui.label;
	infoTx.m_hWid = ui.label->winId();
	infoTx.m_sGuid = m_pDev->m_sPointGuid;
	infoTx.m_nCtrCmd = enCRealPlay;
	infoTx.m_nCtrDevType = enSubDev1;
	if (m_nType == 0)
	{
		infoTx.m_nSubCtrDevType = enCamer;
	}
	else if (m_nType == 1)
	{
		infoTx.m_nSubCtrDevType = enIR;
	}
	bool bTxRet = m_pDev->ctrDev(infoTx);
	if (bTxRet == true)
	{
		m_bIsPlaying = true;
		ui.pushButtonVideoPlay_2->setIcon(QIcon(":/icon/StopPlay.png"));
	}
	return bTxRet;
}

void CVideoLargeDlg::closeEvent(QCloseEvent* event)
{
	endPlayVideo();
	QDialog::closeEvent(event); // 调用父类处理
}

void CVideoLargeDlg::slotPushPlay()
{
	if (m_bIsPlaying)//如果正在播放视频
	{
		endPlayVideo();
		
	}
	else//则播放当前选中的节点
	{
		startPlayVideo();
		
	}
}
